<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item label="保险公司" prop="companyId">
              <el-input v-model="queryParams.company" placeholder="请输入保险公司" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="创建时间"  style="width: 350px">
              <el-date-picker
                v-model="dateRangeCreateTime"
                value-format="YYYY-MM-DD HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
              />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </transition>





    <!-- 图表 -->
    <el-card shadow="never">
      <el-row :gutter="10" class="mt-5">
      <el-col :xs="24" :span="24">
        <charts id="charts" width="100%" height="400px" />
      </el-col>
    </el-row>
    </el-card>



    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['Nyt7StatisticsInsureNumCompany:Nyt7StatisticsInsureNumCompany:export']">导出</el-button>
          </el-col>
          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
      </template>

      <el-table v-loading="loading" :data="Nyt7StatisticsInsureNumCompanyList">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="序号" align="center" prop="id" v-if="true" />
        <el-table-column label="保险公司" align="center" prop="company" />
        <el-table-column label="面积亩数" align="center" prop="areaAcres" />
        <el-table-column label="面积占比" align="center" prop="areaRatio" />
        <el-table-column label="创建时间" align="center" prop="createTime" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" :total="total" @pagination="getList" />
    </el-card>
  </div>
</template>

<script setup name="Nyt7StatisticsInsureNumCompany" lang="ts">

import charts from '../claim_charts/charts.vue';

import { listNyt7StatisticsInsureNumCompany } from '@/api/Nyt7StatisticsInsureNumCompany/Nyt7StatisticsInsureNumCompany';
import { Nyt7StatisticsInsureNumCompanyVO, Nyt7StatisticsInsureNumCompanyQuery, Nyt7StatisticsInsureNumCompanyForm } from '@/api/Nyt7StatisticsInsureNumCompany/Nyt7StatisticsInsureNumCompany/types';
// import { Nyt7RegionManagementVO } from '@/api/Nyt7RegionManagement/Nyt7RegionManagement/types';
// import { listNyt7RegionManagement } from '@/api/Nyt7RegionManagement/Nyt7RegionManagement';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;

const Nyt7StatisticsInsureNumCompanyList = ref<Nyt7StatisticsInsureNumCompanyVO[]>([]);
const loading = ref(true);
const showSearch = ref(true);

const total = ref(0);
const dateRangeCreateTime = ref<[DateModelType, DateModelType]>(['', '']);

const queryFormRef = ref<ElFormInstance>();
// //dinghies区域管理数据和选项
// const companyManagementList = ref<Nyt7RegionManagementVO[]>([]);
// const cityOptions = ref<Nyt7RegionManagementVO[]>([]);
// const countyOptions = ref<Nyt7RegionManagementVO[]>([]);

const initFormData: Nyt7StatisticsInsureNumCompanyForm = {
  company: undefined
}
const data = reactive<PageData<Nyt7StatisticsInsureNumCompanyForm, Nyt7StatisticsInsureNumCompanyQuery>>({
  form: {...initFormData},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    company: undefined,
    params: {
      createTime: undefined,
    }
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);


// //获取区域管理数据的方法
// const getCompanyManagementList = async () => {
//   const res = await listNyt7CompanyManagement();
//   companyManagementList.value = res.data;
//   cityOptions.value = companyManagementList.value.filter(item => item.parentId === 130000); // 假设parentId为0的是市
// };
//
// //处理市的选择变化
// const handleCityChange = (cityName: string) => {
//   const selectedCity = cityOptions.value.find((region) => region.regionName === cityName);
//   if (selectedCity) {
//     countyOptions.value = companyManagementList.value.filter((item) => item.parentId === selectedCity.regionId);
//   } else {
//     countyOptions.value = [];
//   }
// };

/** 查询统计分析_投保统计_数量统计_按地区的数量统计列表 */
const getList = async () => {
  loading.value = true;
  queryParams.value.params = {};
  proxy?.addDateRange(queryParams.value, dateRangeCreateTime.value, 'CreateTime');
  const res = await listNyt7StatisticsInsureNumCompany(queryParams.value);
  Nyt7StatisticsInsureNumCompanyList.value = res.rows;
  console.log(res);
  total.value = res.total;
  loading.value = false;
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
const resetQuery = () => {
  dateRangeCreateTime.value = ['', ''];
  queryFormRef.value?.resetFields();
  handleQuery();
}



/** 导出按钮操作 */
const handleExport = () => {
  proxy?.download(
    'Nyt7StatisticsInsureNumCompany/Nyt7StatisticsInsureNumCompany/export',
    {
      ...queryParams.value
  }, `Nyt7StatisticsInsureNumCompany_${new Date().getTime()}.xlsx`)
}

onMounted(() => {
  getList();
  // getCompanyManagementList();
});
</script>
